<?php

class CategoryController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
    	$this->view->content = "Please select a category";
    	
    }
    public function listproductsAction(){
    	/*Get the parameters passed
    	 * Build query based on the value passed in type
    	 */
    	
    	if($this->_hasParam('value') && $this->_hasParam('type')){
    	$params = $this->_request->getParams();
    	require_once APPLICATION_PATH . '/models/db/db.php';
    	$db = db_db::db_con();
    		if($params['type'] == 'category') {
    			$categories = db_db::categoryGroup($params['value']);
    			$sql_statement = "Select p.productid as productid, pd.description as description,
    					 pd3.description as l_description from product p
    					 JOIN productdescriptions pd on p.productid = pd.productid and pd.type = 2
    					 JOIN productdescriptions pd3 on p.productid = pd3.productid and pd3.type = 3
    					 where p.categoryid in(".$categories.")";
    			$result = $db->query($sql_statement);
    			$db->closeConnection();		
    		}
    		elseif($params['type'] == 'search'){
    			$sql_statement = "Select p.productid as productid,
    							pd.description as description,
    							pd3.description as l_description
    							from product p
    							JOIN productkeywords pk 
    							ON p.productid = pk.productid
    							JOIN productdescriptions pd 
    							ON p.productid = pd.productid and pd.type = 2
    					 		JOIN productdescriptions pd3 
    					 		on p.productid = pd3.productid and pd3.type = 3
    					 		WHERE pk.keywords like '%".$params['value']."%'";
    			$result = $db->query($sql_statement);
    			$db->closeConnection();		
    		}
    	$this->view->result = $result;
    	}
    }
    


}

